<?php

namespace app\common\model;


use think\Model;

class RefundLog extends Model
{
    const REFUND_TYPE_APPY = 1; //提交退款申请
    const REFUND_TYPE_AUDIT = 2; //退款审核成功
    const REFUND_TYPE_FAILED = 3; //退款审核失败
    const REFUND_TYPE_PAY = 4; //退款支付成功
    const REFUND_TYPE_CANCEL = 5; //取消退款
    const REFUND_TYPE_EXPIRED = 6 ; //过期自动退款
    protected  $_type = [
         1 => '提交退款申请时间',
         2 => '退款审核成功时间',
         3 => '退款审核失败时间',
         4 => '退款支付时间',
         5 => '取消退款时间',
         6 => '过期自动退款'

    ];

    /***
     * @param $refund_id 退款表id
     * @param $type 操作类型
     * @param $msg 操作描述
     * 退款操作记录表
     */
    public function refundLog($refund_id,$type, $msg)
    {
        $log = [
            'refund_id'   => $refund_id,
            'type'        => $type,
            // 'msg'         => $msg,
            'create_time' => time()
        ];

        $this->allowField(true)->save($log);
    }

    /***
     * @param int $refund_id
     * 退款操作记录
     */
    public function getRefundLog($refund_id)
    {
        $list = $this->where('refund_id',$refund_id)->select();

        foreach ($list as &$value){
            $value['create_time'] = date('Y-m-d H:i:s', $value['create_time']);
            $value['type'] = $this->_type[$value['type']];
        }

        return $list;
    }
}